import { createStore } from 'redux'

// 初始值
const initState = {
  count: 1,
}

// reducer 函数
function reducer(state = initState, action) {
  console.warn('Redux Logger', { oldState: state, action })
  switch (action.type) {
    case 'add':
      return { ...state, count: state.count + action.payload }
    case 'minus':
      return { ...state, count: state.count - action.payload }
    default:
      return state
  }
}

// 创建仓库实例
const store = createStore(reducer)

// 导出仓库实例
export default store
